// Copyright (C) 2022 Linlexiao
#include "pailabel.h"

#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
#include <QGuiApplication>
#include <QMap>
#include <QScreen>
#include <cmath>

QMap<QString, QPixmap> PaiLabel::paiPicture;
int PaiLabel::SIZE;

void PaiLabel::resizeEvent(QResizeEvent* event) { qDebug() << event->size(); }

PaiLabel::PaiLabel(QWidget* parent) : QLabel(parent) {
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    setAlignment(Qt::AlignBottom);
    hide();
}

void PaiLabel::init() {
    //    auto screenWidth =
    //    QGuiApplication::primaryScreen()->geometry().width(); auto scaleFactor
    //    =
    //        QGuiApplication::primaryScreen()->logicalDotsPerInch() / 96;
    //    screenWidth /= scaleFactor;
    //    qDebug() << screenWidth;

    //    //测试得出 在1920宽度下 92大小合适 这里按照屏幕大小进行缩放
    //    SIZE = floor(static_cast<double>(92) / 1920 * screenWidth);
    SIZE = 92;
    PaiLabel::paiPicture = {
        std::map<QString, QPixmap>::value_type(
            "0m", QPixmap(":/src/img/0m.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "0p", QPixmap(":/src/img/0p.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "0s", QPixmap(":/src/img/0s.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "1m", QPixmap(":/src/img/1m.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "1p", QPixmap(":/src/img/1p.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "1s", QPixmap(":/src/img/1s.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "1z", QPixmap(":/src/img/1z.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "2m", QPixmap(":/src/img/2m.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "2p", QPixmap(":/src/img/2p.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "2s", QPixmap(":/src/img/2s.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "2z", QPixmap(":/src/img/2z.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "3m", QPixmap(":/src/img/3m.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "3p", QPixmap(":/src/img/3p.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "3s", QPixmap(":/src/img/3s.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "3z", QPixmap(":/src/img/3z.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "4m", QPixmap(":/src/img/4m.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "4p", QPixmap(":/src/img/4p.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "4s", QPixmap(":/src/img/4s.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "4z", QPixmap(":/src/img/4z.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "5m", QPixmap(":/src/img/5m.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "5p", QPixmap(":/src/img/5p.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "5s", QPixmap(":/src/img/5s.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "5z", QPixmap(":/src/img/5z.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "6m", QPixmap(":/src/img/6m.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "6p", QPixmap(":/src/img/6p.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "6s", QPixmap(":/src/img/6s.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "6z", QPixmap(":/src/img/6z.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "7m", QPixmap(":/src/img/7m.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "7p", QPixmap(":/src/img/7p.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "7s", QPixmap(":/src/img/7s.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "7z", QPixmap(":/src/img/7z.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "8m", QPixmap(":/src/img/8m.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "8p", QPixmap(":/src/img/8p.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "8s", QPixmap(":/src/img/8s.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "9m", QPixmap(":/src/img/9m.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "9p", QPixmap(":/src/img/9p.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "9s", QPixmap(":/src/img/9s.png")
                      .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "B", QPixmap(":/src/img/B.png")
                     .scaledToHeight(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H0m", QPixmap(":/src/img/H0m.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H0p", QPixmap(":/src/img/H0p.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H0s", QPixmap(":/src/img/H0s.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H1m", QPixmap(":/src/img/H1m.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H1p", QPixmap(":/src/img/H1p.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H1s", QPixmap(":/src/img/H1s.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H1z", QPixmap(":/src/img/H1z.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H2m", QPixmap(":/src/img/H2m.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H2p", QPixmap(":/src/img/H2p.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H2s", QPixmap(":/src/img/H2s.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H2z", QPixmap(":/src/img/H2z.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H3m", QPixmap(":/src/img/H3m.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H3p", QPixmap(":/src/img/H3p.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H3s", QPixmap(":/src/img/H3s.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H3z", QPixmap(":/src/img/H3z.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H4m", QPixmap(":/src/img/H4m.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H4p", QPixmap(":/src/img/H4p.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H4s", QPixmap(":/src/img/H4s.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H4z", QPixmap(":/src/img/H4z.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H5m", QPixmap(":/src/img/H5m.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H5p", QPixmap(":/src/img/H5p.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H5s", QPixmap(":/src/img/H5s.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H5z", QPixmap(":/src/img/H5z.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H6m", QPixmap(":/src/img/H6m.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H6p", QPixmap(":/src/img/H6p.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H6s", QPixmap(":/src/img/H6s.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H6z", QPixmap(":/src/img/H6z.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H7m", QPixmap(":/src/img/H7m.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H7p", QPixmap(":/src/img/H7p.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H7s", QPixmap(":/src/img/H7s.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H7z", QPixmap(":/src/img/H7z.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H8m", QPixmap(":/src/img/H8m.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H8p", QPixmap(":/src/img/H8p.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H8s", QPixmap(":/src/img/H8s.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H9m", QPixmap(":/src/img/H9m.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H9p", QPixmap(":/src/img/H9p.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),
        std::map<QString, QPixmap>::value_type(
            "H9s", QPixmap(":/src/img/H9s.png")
                       .scaledToWidth(SIZE, Qt::SmoothTransformation)),

    };
}

void PaiLabel::setPai(const QString& s) {
    //    QPixmap x = QPixmap(":/src/"+fileName);
    //    x = x.scaled(100,100,Qt::KeepAspectRatio,Qt::SmoothTransformation);
    show();
    setPixmap(PaiLabel::paiPicture[s]);
}

void PaiLabel::removePai() { hide(); }
